/*
 * Copyright (c) 2002-2003 by OpenSymphony
 * All rights reserved.
 */
package org.jackysoft.opensymphony.workflow.entity;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;


/**
 * A validator is a helper used to verify values in the input map that is
 * provided to every action call.
 *
 * 
 */


public class ValidatorDescriptor extends AbstractDescriptor {
    //~ Instance fields ////////////////////////////////////////////////////////

    /**
	 * 
	 */
	private static final long serialVersionUID = 5139144867093951766L;
	protected Map args = new HashMap();
    protected String name;
    protected String type;

    //~ Constructors ///////////////////////////////////////////////////////////

    /**
     * 
     */
    public ValidatorDescriptor() {
    }
  
    /**
     * 
     */
    public ValidatorDescriptor(org.dom4j.Element element) {
    	super(element);this.init(element);
    }

    //~ Methods ////////////////////////////////////////////////////////////////
    public Map getArgs() {
        return args;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getType() {
        return type;
    }   

    @Override
    protected void init(org.dom4j.Element validator) {
    	type = validator.attributeValue("type");
    	name = validator.attributeValue("name");
    	
    	try {
    		setId(Integer.parseInt(validator.attributeValue("id")));
    	} catch (NumberFormatException e) {
    	}
    	
    	this.args = new HashMap();
    	for(Iterator argItr = validator.elementIterator("arg");argItr.hasNext();){
    		org.dom4j.Element argEle = (org.dom4j.Element) argItr.next();
    		this.args.put(argEle.attributeValue("name"), argEle.getText());
    	}    	
    	
    }
    
	/**
	 * 
	 */
	public void setArgs(Map args) {
		this.args = args;
	}
}
